package com.data.center.service.impl;

import com.data.center.dictionary.OrganizationCategory;
import com.data.center.dictionary.OrganizationStatus;
import com.data.center.dto.OrganizationDto;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@SpringBootTest
@Slf4j
class neoNeoOrganizationServiceImplTestAC {

    @Autowired
    OrganizationServiceImpl organizationService;

    @Test
    void findOrganization() {
        log.info(organizationService.findOrganization("错误", "测试").toString());
        log.info(organizationService.findOrganization("错误的", "测试1").toString());
        log.info(organizationService.findOrganization("错误的", "测试2").toString());
        log.info(organizationService.findOrganization("错误的", null).toString());
        log.info(organizationService.findOrganization(null, "测试1").toString());
    }

    @Test
    void add() {
        addOrganization1();
        addOrganization2();
        addOrganization3();
        addOrganization4();
        addOrganization5();
    }

    @Test
    void addOrganization1() {
        OrganizationDto organization = new OrganizationDto();
        organization.setName("机构全名称 1 ,.[]<>()s '\"xx");

        List<String> abbreviationList = new ArrayList<>();
        abbreviationList.add("机构全名1");
        abbreviationList.add("机构1");
        organization.setAbbreviation(abbreviationList);

        organization.setCategory(OrganizationCategory.UNKNOWN.getKey());
        organization.setUscc("USCC123");
        organization.setRepresentative("Representative");
        organization.setDescription("Description");
        organization.setCountry("CHN");
        organization.setDivisionCode("03110000");
        organization.setAddress("Address");
        organization.setPostCode("Post Code");
        organization.setStatus(Integer.valueOf(OrganizationStatus.NOT_REVIEWED.getKey()));
        organization.setApprover("Approver");
        organization.setApprovalTime(new Date());

        organizationService.addOrganization(organization);
    }
    @Test
    void addOrganization2() {
        OrganizationDto organization = new OrganizationDto();
        organization.setName("机构全名称 2 ");

        List<String> abbreviationList = new ArrayList<>();
        abbreviationList.add("机构全名2 ");
        abbreviationList.add("机构 2");
        organization.setAbbreviation(abbreviationList);

        organization.setCategory(OrganizationCategory.UNKNOWN.getKey());
        organization.setUscc("USCC123");
        organization.setRepresentative("Representative");
        organization.setDescription("Description");
        organization.setCountry("CHN");
        organization.setDivisionCode("03110000");
        organization.setAddress("Address");
        organization.setPostCode("Post Code");
        organization.setStatus(Integer.valueOf(OrganizationStatus.NOT_REVIEWED.getKey()));
        organization.setApprover("Approver");
        organization.setApprovalTime(new Date());

        organizationService.addOrganization(organization);
    }
    @Test
    void addOrganization3() {
        OrganizationDto organization = new OrganizationDto();
        organization.setName("机构全名称(3）");

        List<String> abbreviationList = new ArrayList<>();
        abbreviationList.add("机构全名（3） ");
        abbreviationList.add("机构 3");
        organization.setAbbreviation(abbreviationList);

        organization.setCategory(OrganizationCategory.UNKNOWN.getKey());
        organization.setUscc("USCC123");
        organization.setRepresentative("Representative");
        organization.setDescription("Description");
        organization.setCountry("CHN");
        organization.setDivisionCode("03110000");
        organization.setAddress("Address");
        organization.setPostCode("Post Code");
        organization.setStatus(Integer.valueOf(OrganizationStatus.NOT_REVIEWED.getKey()));
        organization.setApprover("Approver");
        organization.setApprovalTime(new Date());

        organizationService.addOrganization(organization);
    }
    @Test
    void addOrganization4() {
        OrganizationDto organization = new OrganizationDto();
        organization.setName("机构全名称(4）");

        List<String> abbreviationList = new ArrayList<>();
        abbreviationList.add("机构全名（4）) ");
        abbreviationList.add("机构 4");
        organization.setAbbreviation(abbreviationList);

        organization.setCategory(OrganizationCategory.UNKNOWN.getKey());
        organization.setUscc("USCC123");
        organization.setRepresentative("Representative");
        organization.setDescription("Description");
        organization.setCountry("CHN");
        organization.setDivisionCode("110000"); // 尝试插入一个区域编码可以自动解析的
        organization.setAddress("Address");
        organization.setPostCode("Post Code");
        organization.setStatus(Integer.valueOf(OrganizationStatus.NOT_REVIEWED.getKey()));
        organization.setApprover("Approver");
        organization.setApprovalTime(new Date());

        organizationService.addOrganization(organization);
    }
    @Test
    void addOrganization5() {
        OrganizationDto organization = new OrganizationDto();
        organization.setName("机构全名称((5）)");

        List<String> abbreviationList = new ArrayList<>();
        abbreviationList.add("机构全名(（5） ");
        abbreviationList.add("机构 5");
        organization.setAbbreviation(abbreviationList);

        organization.setCategory("未知"); // 尝试插入一个可以反解析的企业类型名称
        organization.setUscc("USCC123");
        organization.setRepresentative("Representative");
        organization.setDescription("Description");
        organization.setCountry("CHN");
        organization.setDivisionCode("110000");
        organization.setAddress("Address");
        organization.setPostCode("Post Code");
        organization.setStatus(Integer.valueOf(OrganizationStatus.NOT_REVIEWED.getKey()));
        organization.setApprover("Approver");
        organization.setApprovalTime(new Date());

        organizationService.addOrganization(organization);
    }

    @Test
    void addOrganization2Wrong1(){
        OrganizationDto organization = new OrganizationDto();
        organization.setName("机构全名称 3 ");

        List<String> abbreviationList = new ArrayList<>();
        abbreviationList.add("机构全名3 ");
        abbreviationList.add("机构 2"); // 尝试插入一个已经存在的机构简称
        organization.setAbbreviation(abbreviationList);

        organization.setCategory(OrganizationCategory.UNKNOWN.getKey());
        organization.setUscc("USCC123");
        organization.setRepresentative("Representative");
        organization.setDescription("Description");
        organization.setCountry("CHN");
        organization.setDivisionCode("03110000");
        organization.setAddress("Address");
        organization.setPostCode("Post Code");
        organization.setStatus(Integer.valueOf(OrganizationStatus.NOT_REVIEWED.getKey()));
        organization.setApprover("Approver");
        organization.setApprovalTime(new Date());

        organizationService.addOrganization(organization);
    }
    @Test
    void addOrganization2Wrong2() {
        OrganizationDto organization = new OrganizationDto();
        organization.setName("机构全 名称 2 ");// 尝试插入一个已经存在的但是没有空格的机构全称

        List<String> abbreviationList = new ArrayList<>();
        abbreviationList.add("机构全名3 ");
        abbreviationList.add("机构 3");
        organization.setAbbreviation(abbreviationList);

        organization.setCategory(OrganizationCategory.UNKNOWN.getKey());
        organization.setUscc("USCC123");
        organization.setRepresentative("Representative");
        organization.setDescription("Description");
        organization.setCountry("CHN");
        organization.setDivisionCode("03110000");
        organization.setAddress("Address");
        organization.setPostCode("Post Code");
        organization.setStatus(Integer.valueOf(OrganizationStatus.NOT_REVIEWED.getKey()));
        organization.setApprover("Approver");
        organization.setApprovalTime(new Date());

        organizationService.addOrganization(organization);
    }
    @Test
    void addOrganization2Wrong3() {
        OrganizationDto organization = new OrganizationDto();
        organization.setName("机构全 名称 3 ");

        List<String> abbreviationList = new ArrayList<>();
        abbreviationList.add("机构全 名称 2 "); // 尝试插入一个简称为已经存在但是没有空格的机构全称
        abbreviationList.add("机构 3");
        organization.setAbbreviation(abbreviationList);

        organization.setCategory(OrganizationCategory.UNKNOWN.getKey());
        organization.setUscc("USCC123");
        organization.setRepresentative("Representative");
        organization.setDescription("Description");
        organization.setCountry("CHN");
        organization.setDivisionCode("03110000");
        organization.setAddress("Address");
        organization.setPostCode("Post Code");
        organization.setStatus(Integer.valueOf(OrganizationStatus.NOT_REVIEWED.getKey()));
        organization.setApprover("Approver");
        organization.setApprovalTime(new Date());

        organizationService.addOrganization(organization);
    }
    @Test
    void addOrganization2Wrong4() {
        OrganizationDto organization = new OrganizationDto();
        organization.setName("机构2 ");// 尝试插入一个全称为已经存在的机构全称

        List<String> abbreviationList = new ArrayList<>();
        abbreviationList.add("机构全 名称 2 ");
        abbreviationList.add("机构 3");
        organization.setAbbreviation(abbreviationList);

        organization.setCategory(OrganizationCategory.UNKNOWN.getKey());
        organization.setUscc("USCC123");
        organization.setRepresentative("Representative");
        organization.setDescription("Description");
        organization.setCountry("CHN");
        organization.setDivisionCode("03110000");
        organization.setAddress("Address");
        organization.setPostCode("Post Code");
        organization.setStatus(Integer.valueOf(OrganizationStatus.NOT_REVIEWED.getKey()));
        organization.setApprover("Approver");
        organization.setApprovalTime(new Date());

        organizationService.addOrganization(organization);
    }
    @Test
    void addOrganization4wrong1() {
        OrganizationDto organization = new OrganizationDto();
        organization.setName("机构全名称(4）");

        List<String> abbreviationList = new ArrayList<>();
        abbreviationList.add("机构全名（4） ");
        abbreviationList.add("机构 4");
        organization.setAbbreviation(abbreviationList);

        organization.setCategory(OrganizationCategory.UNKNOWN.getKey());
        organization.setUscc("USCC123");
        organization.setRepresentative("Representative");
        organization.setDescription("Description");
        organization.setCountry("CHN");
        organization.setDivisionCode("0311000"); // 尝试插入一个区域编码无法解析的
        organization.setAddress("Address");
        organization.setPostCode("Post Code");
        organization.setStatus(Integer.valueOf(OrganizationStatus.NOT_REVIEWED.getKey()));
        organization.setApprover("Approver");
        organization.setApprovalTime(new Date());

        organizationService.addOrganization(organization);
    }
    @Test
    void addOrganization5wrong1() {
        OrganizationDto organization = new OrganizationDto();
        organization.setName("机构全名称((5）)");

        List<String> abbreviationList = new ArrayList<>();
        abbreviationList.add("机构全名(（5） ");
        abbreviationList.add("机构 5");
        organization.setAbbreviation(abbreviationList);

        organization.setCategory(""); // 尝试插入一个无法解析的企业类型名称
        organization.setUscc("USCC123");
        organization.setRepresentative("Representative");
        organization.setDescription("Description");
        organization.setCountry("CHN");
        organization.setDivisionCode("110000");
        organization.setAddress("Address");
        organization.setPostCode("Post Code");
        organization.setStatus(Integer.valueOf(OrganizationStatus.NOT_REVIEWED.getKey()));
        organization.setApprover("Approver");
        organization.setApprovalTime(new Date());

        organizationService.addOrganization(organization);
    }
    @Test
    void addOrganization5wrong2() {
        OrganizationDto organization = new OrganizationDto();
        organization.setName("机构全名称((5）)");

        List<String> abbreviationList = new ArrayList<>();
        abbreviationList.add("机构全名(（5） ");
        abbreviationList.add("机构 5");
        organization.setAbbreviation(abbreviationList);

        organization.setCategory("00");
        organization.setUscc("USCC123");
        organization.setRepresentative("Representative");
        organization.setDescription("Description");
        organization.setCountry("CHN");
        organization.setDivisionCode(null); // 尝试插入一个空的区域编码
        organization.setAddress("Address");
        organization.setPostCode("Post Code");
        organization.setStatus(Integer.valueOf(OrganizationStatus.NOT_REVIEWED.getKey()));
        organization.setApprover("Approver");
        organization.setApprovalTime(new Date());

        organizationService.addOrganization(organization);
    }
    @Test
    void addOrganization5wrong3() {
        OrganizationDto organization = new OrganizationDto();
        organization.setName("机构全名称((5）)");

        List<String> abbreviationList = new ArrayList<>();
        abbreviationList.add("机构全名(（5） ");
        abbreviationList.add("机构 5");
        organization.setAbbreviation(abbreviationList);

        organization.setCategory("00");
        organization.setUscc("USCC123");
        organization.setRepresentative("Representative");
        organization.setDescription("Description");
        organization.setCountry("CHN");
        organization.setDivisionCode("龙胜各族自治县"); // 尝试插入一个区域名称
        organization.setAddress("Address");
        organization.setPostCode("Post Code");
        organization.setStatus(Integer.valueOf(OrganizationStatus.NOT_REVIEWED.getKey()));
        organization.setApprover("Approver");
        organization.setApprovalTime(new Date());

        organizationService.addOrganization(organization);
    }


//    @Test
//    void renameOrganizationCoverMode() {
//        List<OrganizationDto> old = organizationService.findOrganization("", "机构全名1");// 仅通过一个正确的简称查询旧的机构
//
//        List<String> abbreviationList = new ArrayList<>();
//        abbreviationList.add("机构全名1");
//        abbreviationList.add("机构1");
//        abbreviationList.add("机构全名称 1 ,.[]<>()s '\"xx");
//
//        organizationService.renameOrganizationCoverMode(old.get(0), "机构全名称 1无符号", abbreviationList);
//    }
//
//    @Test
//    void renameOrganizationCoverModeWrong() {
//        List<OrganizationDto> old = organizationService.findOrganization("", "机构全名1"); // 仅通过简称查询旧的机构
//
//        List<String> abbreviationList = new ArrayList<>();
//
//        organizationService.renameOrganizationCoverMode(old.get(0), "教育机构1", abbreviationList); // 清空所有简称，并让名称与原机构无关
//    }
//
//    @Test
//    void renameOrganizationAddAbbreviations() {
//        List<OrganizationDto> old = organizationService.findOrganization("", "机构全名1"); // 仅通过简称查询旧的机构
//
//        organizationService.renameOrganizationAddAbbreviations(old.get(0), "教育1"); // 添加一个新的简称
//    }
//
//    @Test
//    void renameOrganizationAddAbbreviationsWrong1() {
//        List<OrganizationDto> old = organizationService.findOrganization("", "机构全名1"); // 仅通过简称查询旧的机构
//
//        organizationService.renameOrganizationAddAbbreviations(old.get(0), "机构全名称1，。   【】《》(）s‘“xx"); // 尝试添加一个添加了空格、英文符号的原全称作为简称
//    }

    @Test
    void renameOrganization() {
    }
}